//////////////////////////////////////////////////////////////////////////
public:
	/// <summary>
	/// this function is used to set some external parameters in case of X Window
	/// </summary>
	/// <param name="argc"></param>
	/// <returns></returns>
	static int InitSystem(int argc, IntPtr argv)
	{
		return cvInitSystem(argc, (char**)argv.ToPointer());
	}

	/// <summary>
	/// </summary>
	/// <returns></returns>
	static int StartWindowThread()
	{
		return cvStartWindowThread();
	}

	/// <summary>
	/// create window
	/// </summary>
	/// <param name="name"></param>
	/// <returns></returns>
	static int NamedWindow(IntPtr name, WindowMode flags)
	{
		return cvNamedWindow((char*)name.ToPointer(), (int)flags);
	}

	/// <summary>
	/// create window
	/// </summary>
	/// <returns></returns>
	static int NamedWindow(IntPtr name)
	{
		return cvNamedWindow((char*)name.ToPointer());
	}

	/// <summary>
	/// display image within window (highgui windows remember their content)
	/// </summary>
	/// <param name="name"></param>
	static void ShowImage(IntPtr name, IntPtr image)
	{
		cvShowImage((char*)name.ToPointer(), (CvArr*)image.ToPointer());
	}

	/// <summary>
	/// resize/move window
	/// </summary>
	/// <param name="name"></param>
	/// <param name="width"></param>
	static void ResizeWindow(IntPtr name, int width, int height)
	{
		cvResizeWindow((char*)name.ToPointer(), width, height);
	}

	/// <summary>
	/// </summary>
	/// <param name="name"></param>
	/// <param name="x"></param>
	static void MoveWindow(IntPtr name, int x, int y)
	{
		cvMoveWindow((char*)name.ToPointer(), x, y);
	}

	/// <summary>
	/// destroy window and all the trackers associated with it
	/// </summary>
	static void DestroyWindow(IntPtr name)
	{
		cvDestroyWindow((char*)name.ToPointer());
	}

	/// <summary>
	/// </summary>
	static void DestroyAllWindows()
	{
		cvDestroyAllWindows();
	}

	/// <summary>
	/// get native window handle (HWND in case of Win32 and Widget in case of X Window)
	/// </summary>
	/// <returns></returns>
	static IntPtr GetWindowHandle(IntPtr name)
	{
		return IntPtr(cvGetWindowHandle((char*)name.ToPointer()));
	}

	/// <summary>
	/// get name of highgui window given its native handle
	/// </summary>
	/// <returns></returns>
	static IntPtr GetWindowName(IntPtr window_handle)
	{
		return IntPtr((void*)cvGetWindowName((void*)window_handle.ToPointer()));
	}

	/// <summary>
	/// create trackbar and display it on top of given window, set callback
	/// </summary>
	/// <param name="trackbar_name"></param>
	/// <param name="window_name"></param>
	/// <param name="value"></param>
	/// <param name="count"></param>
	/// <returns></returns>
	static int CreateTrackbar(IntPtr trackbar_name, IntPtr window_name, IntPtr value, int count, TrackbarCallback^ on_change)
	{
		return cvCreateTrackbar((char*)trackbar_name.ToPointer(), (char*)window_name.ToPointer(), (int*)value.ToPointer(), count, 
			(CvTrackbarCallback)Marshal::GetFunctionPointerForDelegate(on_change).ToPointer());
	}

	/// <summary>
	/// </summary>
	/// <param name="trackbar_name"></param>
	/// <param name="window_name"></param>
	/// <param name="value"></param>
	/// <param name="count"></param>
	/// <param name="on_change"></param>
	/// <returns></returns>
	static int CreateTrackbar2(IntPtr trackbar_name, IntPtr window_name, IntPtr value, int count, TrackbarCallback2^ on_change, IntPtr userdata)
	{
		return cvCreateTrackbar2((char*)trackbar_name.ToPointer(), (char*)window_name.ToPointer(), (int*)value.ToPointer(), count, 
			(CvTrackbarCallback2)Marshal::GetFunctionPointerForDelegate(on_change).ToPointer(), (void*)userdata.ToPointer());
	}

	/// <summary>
	/// </summary>
	/// <param name="trackbar_name"></param>
	/// <param name="window_name"></param>
	/// <param name="value"></param>
	/// <param name="count"></param>
	/// <returns></returns>
	static int CreateTrackbar2(IntPtr trackbar_name, IntPtr window_name, IntPtr value, int count, TrackbarCallback2^ on_change)
	{
		return cvCreateTrackbar2((char*)trackbar_name.ToPointer(), (char*)window_name.ToPointer(), (int*)value.ToPointer(), count, 
			(CvTrackbarCallback2)Marshal::GetFunctionPointerForDelegate(on_change).ToPointer());
	}

	/// <summary>
	/// retrieve or set trackbar position
	/// </summary>
	/// <param name="trackbar_name"></param>
	/// <returns></returns>
	static int GetTrackbarPos(IntPtr trackbar_name, IntPtr window_name)
	{
		return cvGetTrackbarPos((char*)trackbar_name.ToPointer(), (char*)window_name.ToPointer());
	}

	/// <summary>
	/// </summary>
	/// <param name="trackbar_name"></param>
	/// <param name="window_name"></param>
	static void SetTrackbarPos(IntPtr trackbar_name, IntPtr window_name, int pos)
	{
		cvSetTrackbarPos((char*)trackbar_name.ToPointer(), (char*)window_name.ToPointer(), pos);
	}

	/// <summary>
	/// assign callback for mouse events
	/// </summary>
	/// <param name="window_name"></param>
	/// <param name="on_mouse"></param>
	static void SetMouseCallback(IntPtr window_name, MouseCallback^ on_mouse, IntPtr param)
	{
		cvSetMouseCallback((char*)window_name.ToPointer(), 
			(CvMouseCallback)Marshal::GetFunctionPointerForDelegate(on_mouse).ToPointer(), (void*)param.ToPointer());
	}

	/// <summary>
	/// assign callback for mouse events
	/// </summary>
	/// <param name="window_name"></param>
	static void SetMouseCallback(IntPtr window_name, MouseCallback^ on_mouse)
	{
		cvSetMouseCallback((char*)window_name.ToPointer(), 
			(CvMouseCallback)Marshal::GetFunctionPointerForDelegate(on_mouse).ToPointer());
	}

	/// <summary>
	/// load image from file
	/// iscolor can be a combination of above flags where CV_LOAD_IMAGE_UNCHANGED
	/// overrides the other flags
	/// using CV_LOAD_IMAGE_ANYCOLOR alone is equivalent to CV_LOAD_IMAGE_UNCHANGED
	/// unless CV_LOAD_IMAGE_ANYDEPTH is specified images are converted to 8bit
	/// </summary>
	/// <param name="filename"></param>
	/// <returns></returns>
	static IntPtr LoadImage(IntPtr filename, LoadImageFlag iscolor)
	{
		return IntPtr(cvLoadImage((char*)filename.ToPointer(), (int)iscolor));
	}

	/// <summary>
	/// load image from file
	/// iscolor can be a combination of above flags where CV_LOAD_IMAGE_UNCHANGED
	/// overrides the other flags
	/// using CV_LOAD_IMAGE_ANYCOLOR alone is equivalent to CV_LOAD_IMAGE_UNCHANGED
	/// unless CV_LOAD_IMAGE_ANYDEPTH is specified images are converted to 8bit
	/// </summary>
	/// <returns></returns>
	static IntPtr LoadImage(IntPtr filename)
	{
		return IntPtr(cvLoadImage((char*)filename.ToPointer()));
	}

	/// <summary>
	/// </summary>
	/// <param name="filename"></param>
	/// <returns></returns>
	static IntPtr LoadImageM(IntPtr filename, LoadImageFlag iscolor)
	{
		return IntPtr(cvLoadImageM((char*)filename.ToPointer(), (int)iscolor));
	}

	/// <summary>
	/// </summary>
	/// <returns></returns>
	static IntPtr LoadImageM(IntPtr filename)
	{
		return IntPtr(cvLoadImageM((char*)filename.ToPointer()));
	}

	/// <summary>
	/// save image to file
	/// </summary>
	/// <param name="filename"></param>
	/// <param name="image"></param>
	/// <returns></returns>
	static int SaveImage(IntPtr filename, IntPtr image, IntPtr params)
	{
		return cvSaveImage((char*)filename.ToPointer(), (CvArr*)image.ToPointer(), (int*)params.ToPointer());
	}

	/// <summary>
	/// save image to file
	/// </summary>
	/// <param name="filename"></param>
	/// <returns></returns>
	static int SaveImage(IntPtr filename, IntPtr image)
	{
		return cvSaveImage((char*)filename.ToPointer(), (CvArr*)image.ToPointer());
	}

	/// <summary>
	/// decode image stored in the buffer
	/// </summary>
	/// <param name="buf"></param>
	/// <returns></returns>
	static IntPtr DecodeImage(IntPtr buf, LoadImageFlag iscolor)
	{
		return IntPtr(cvDecodeImage((CvMat*)buf.ToPointer(), (int)iscolor));
	}

	/// <summary>
	/// decode image stored in the buffer
	/// </summary>
	/// <returns></returns>
	static IntPtr DecodeImage(IntPtr buf)
	{
		return IntPtr(cvDecodeImage((CvMat*)buf.ToPointer()));
	}

	/// <summary>
	/// </summary>
	/// <param name="buf"></param>
	/// <returns></returns>
	static IntPtr DecodeImageM(IntPtr buf, LoadImageFlag iscolor)
	{
		return IntPtr(cvDecodeImageM((CvMat*)buf.ToPointer(), (int)iscolor));
	}

	/// <summary>
	/// </summary>
	/// <returns></returns>
	static IntPtr DecodeImageM(IntPtr buf)
	{
		return IntPtr(cvDecodeImageM((CvMat*)buf.ToPointer()));
	}

	/// <summary>
	/// encode image and store the result as a byte vector (single-row 8uC1 matrix)
	/// </summary>
	/// <param name="ext"></param>
	/// <param name="image"></param>
	/// <returns></returns>
	static IntPtr EncodeImage(IntPtr ext, IntPtr image, IntPtr params)
	{
		return IntPtr(cvEncodeImage((char*)ext.ToPointer(), (CvArr*)image.ToPointer(), (int*)params.ToPointer()));
	}

	/// <summary>
	/// encode image and store the result as a byte vector (single-row 8uC1 matrix)
	/// </summary>
	/// <param name="ext"></param>
	/// <returns></returns>
	static IntPtr EncodeImage(IntPtr ext, IntPtr image)
	{
		return IntPtr(cvEncodeImage((char*)ext.ToPointer(), (CvArr*)image.ToPointer()));
	}

	/// <summary>
	/// utility function: convert one image to another with optional vertical flip
	/// </summary>
	/// <param name="src"></param>
	/// <param name="dst"></param>
	static void ConvertImage(IntPtr src, IntPtr dst, ConvertImageFlag flags)
	{
		cvConvertImage((CvArr*)src.ToPointer(), (CvArr*)dst.ToPointer(), (int)flags);
	}

	/// <summary>
	/// utility function: convert one image to another with optional vertical flip
	/// </summary>
	/// <param name="src"></param>
	static void ConvertImage(IntPtr src, IntPtr dst)
	{
		cvConvertImage((CvArr*)src.ToPointer(), (CvArr*)dst.ToPointer());
	}

	/// <summary>
	/// wait for key event infinitely (delay<=0) or for "delay" milliseconds
	/// </summary>
	/// <returns></returns>
	static int WaitKey(int delay)
	{
		return cvWaitKey(delay);
	}

	/// <summary>
	/// wait for key event infinitely (delay<=0) or for "delay" milliseconds
	/// </summary>
	/// <returns></returns>
	static int WaitKey()
	{
		return cvWaitKey();
	}

	/// <summary>
	/// start capturing frames from video file
	/// </summary>
	/// <returns></returns>
	static IntPtr CreateFileCapture(IntPtr filename)
	{
		return IntPtr(cvCreateFileCapture((char*)filename.ToPointer()));
	}

	/// <summary>
	/// start capturing frames from camera: index = camera_index + domain_offset (CV_CAP_*)
	/// </summary>
	/// <returns></returns>
	static IntPtr CreateCameraCapture(CaptureDeviceFlag index)
	{
		return IntPtr(cvCreateCameraCapture((int)index));
	}

	/// <summary>
	/// grab a frame, return 1 on success, 0 on fail.
	/// this function is thought to be fast
	/// </summary>
	/// <returns></returns>
	static int GrabFrame(IntPtr capture)
	{
		return cvGrabFrame((CvCapture*)capture.ToPointer());
	}

	/// <summary>
	/// get the frame grabbed with cvGrabFrame(..)
	/// This function may apply some frame processing like
	/// frame decompression, flipping etc.
	/// !!!DO NOT RELEASE or MODIFY the retrieved frame!!!
	/// </summary>
	/// <param name="capture"></param>
	/// <returns></returns>
	static IntPtr RetrieveFrame(IntPtr capture, CaptureDeviceFlag streamIdx)
	{
		return IntPtr(cvRetrieveFrame((CvCapture*)capture.ToPointer(), (int)streamIdx));
	}

	/// <summary>
	/// get the frame grabbed with cvGrabFrame(..)
	/// This function may apply some frame processing like
	/// frame decompression, flipping etc.
	/// !!!DO NOT RELEASE or MODIFY the retrieved frame!!!
	/// </summary>
	/// <returns></returns>
	static IntPtr RetrieveFrame(IntPtr capture)
	{
		return IntPtr(cvRetrieveFrame((CvCapture*)capture.ToPointer()));
	}

	/// <summary>
	/// Just a combination of cvGrabFrame and cvRetrieveFrame
	/// !!!DO NOT RELEASE or MODIFY the retrieved frame!!!
	/// </summary>
	/// <returns></returns>
	static IntPtr QueryFrame(IntPtr capture)
	{
		return IntPtr(cvQueryFrame((CvCapture*)capture.ToPointer()));
	}

	/// <summary>
	/// stop capturing/reading and free resources
	/// </summary>
	static void ReleaseCapture(IntPtr capture)
	{
		cvReleaseCapture((CvCapture**)capture.ToPointer());
	}

	/// <summary>
	/// retrieve or set capture properties
	/// </summary>
	/// <param name="capture"></param>
	/// <returns></returns>
	static double GetCaptureProperty(IntPtr capture, CapturePropType property_id)
	{
		return cvGetCaptureProperty((CvCapture*)capture.ToPointer(), (int)property_id);
	}

	/// <summary>
	/// </summary>
	/// <param name="capture"></param>
	/// <param name="property_id"></param>
	/// <returns></returns>
	static int SetCaptureProperty(IntPtr capture, CapturePropType property_id, double value)
	{
		return cvSetCaptureProperty((CvCapture*)capture.ToPointer(), (int)property_id, value);
	}

	/// <summary>
	/// Return the type of the capturer (eg, CV_CAP_V4W, CV_CAP_UNICAP), which is unknown if created with CV_CAP_ANY
	/// </summary>
	/// <returns></returns>
	static int GetCaptureDomain(IntPtr capture)
	{
		return cvGetCaptureDomain((CvCapture*)capture.ToPointer());
	}

	/// <summary>
	/// initialize video file writer
	/// </summary>
	/// <param name="filename"></param>
	/// <param name="fourcc"></param>
	/// <param name="fps"></param>
	/// <param name="frame_size"></param>
	/// <returns></returns>
	static IntPtr CreateVideoWriter(IntPtr filename, int fourcc, double fps, NAMESPACE::Size2D32s frame_size, int is_color)
	{
		return IntPtr(cvCreateVideoWriter((char*)filename.ToPointer(), fourcc, fps, *(CvSize*)&frame_size, is_color));
	}

	/// <summary>
	/// initialize video file writer
	/// </summary>
	/// <param name="filename"></param>
	/// <param name="fourcc"></param>
	/// <param name="fps"></param>
	/// <returns></returns>
	static IntPtr CreateVideoWriter(IntPtr filename, int fourcc, double fps, NAMESPACE::Size2D32s frame_size)
	{
		return IntPtr(cvCreateVideoWriter((char*)filename.ToPointer(), fourcc, fps, *(CvSize*)&frame_size));
	}

	/// <summary>
	/// write frame to video file
	/// </summary>
	/// <param name="writer"></param>
	/// <returns></returns>
	static int WriteFrame(IntPtr writer, IntPtr image)
	{
		return cvWriteFrame((CvVideoWriter*)writer.ToPointer(), (IplImage*)image.ToPointer());
	}

	/// <summary>
	/// close video file writer
	/// </summary>
	static void ReleaseVideoWriter(IntPtr writer)
	{
		cvReleaseVideoWriter((CvVideoWriter**)writer.ToPointer());
	}

	/// <summary>
	/// </summary>
	static void SetPreprocessFuncWin32(Win32WindowCallback^ on_preprocess)
	{
		cvSetPreprocessFuncWin32((CvWin32WindowCallback)Marshal::GetFunctionPointerForDelegate(on_preprocess).ToPointer());
	}

	/// <summary>
	/// </summary>
	static void SetPostprocessFuncWin32(Win32WindowCallback^ on_postprocess)
	{
		cvSetPostprocessFuncWin32((CvWin32WindowCallback)Marshal::GetFunctionPointerForDelegate(on_postprocess).ToPointer());
	}

//////////////////////////////////////////////////////////////////////////